package com.qzdsoft.erpcloud.service.sys.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.qzdsoft.erpcloud.domain.sys.SysTableAuthField;
import com.qzdsoft.erpcloud.mapper.sys.SysTableAuthFieldMapper;
import com.qzdsoft.erpcloud.service.sys.SysTableAuthFieldService;
import com.qzdsoft.erpcloud.vo.sys.SysTableAuthFieldInfo;
import com.qzdsoft.erpcloud.vo.sys.SysTableAuthFieldQueryInfo;
import com.qzdsoft.vo.LayTableResponse;
import com.qzdsoft.vo.Response;

/**
 * Created by Admin
 */
@Service
public class SysTableAuthFieldServiceImpl implements SysTableAuthFieldService {

    @Autowired
    private SysTableAuthFieldMapper sysTableAuthFieldMapper;

    @Override
    public SysTableAuthField selectById(Integer id) {
        return sysTableAuthFieldMapper.selectByPrimaryKey(id);
    }

    @Override
    public Response saveOrUpd(SysTableAuthField info) {
        if(null != info.getId()){
        	SysTableAuthField field= sysTableAuthFieldMapper.selectByPrimaryKey(info.getId());
        	field.setField(info.getField());
        	field.setField_name(info.getField_name());
        	info.setField_name_display(info.getField_name_display());
            sysTableAuthFieldMapper.updateByPrimaryKey(field);
        } else {
        	info.setCtime(new Date());
            sysTableAuthFieldMapper.insert(info);
        }
        return Response.success(null);
    }

    @Override
    public Response delete(Integer id) {
        sysTableAuthFieldMapper.deleteByPrimaryKey(id);
        return Response.success(null);
    }


    @Override
    public LayTableResponse<SysTableAuthField> selectData(SysTableAuthFieldQueryInfo info) {
    	PageHelper.startPage(info.getPage(), info.getLimit());
        return new LayTableResponse<SysTableAuthField>(sysTableAuthFieldMapper.selectData(info));
    }

	@Override
	public List<SysTableAuthFieldInfo> selectByTableId(Integer tableId,Integer roleId) {
		// TODO Auto-generated method stub
		return sysTableAuthFieldMapper.selectByTableId(tableId,roleId);
	}
    
    
}
